home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 March / Pc Users extra 6.iso / pshare95 / prog / formula1 / vcform1.z / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-10-20  |  16.0 KB  |  468 lines

  1. VERSION 5.00
  2. Object = "{13E51000-A52B-11D0-86DA-00608CB9FBFB}#5.0#0"; "VCF15.OCX"
  3. Begin VB.Form frmMain 
  4.    Caption         =   "Smallville Genealogical Society"
  5.    ClientHeight    =   6060
  6.    ClientLeft      =   1650
  7.    ClientTop       =   1935
  8.    ClientWidth     =   9525
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   6060
  11.    ScaleWidth      =   9525
  12.    Begin VB.CommandButton cmdNew 
  13.       Caption         =   ">*"
  14.       BeginProperty Font 
  15.          Name            =   "Arial"
  16.          Size            =   14.25
  17.          Charset         =   0
  18.          Weight          =   400
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   375
  24.       Left            =   4920
  25.       Style           =   1  'Graphical
  26.       TabIndex        =   6
  27.       Top             =   5520
  28.       Width           =   495
  29.    End
  30.    Begin VB.CommandButton cmdLast 
  31.       Caption         =   ">I"
  32.       BeginProperty Font 
  33.          Name            =   "Arial"
  34.          Size            =   14.25
  35.          Charset         =   0
  36.          Weight          =   400
  37.          Underline       =   0   'False
  38.          Italic          =   0   'False
  39.          Strikethrough   =   0   'False
  40.       EndProperty
  41.       Height          =   375
  42.       Left            =   4440
  43.       Style           =   1  'Graphical
  44.       TabIndex        =   5
  45.       Top             =   5520
  46.       Width           =   495
  47.    End
  48.    Begin VB.CommandButton cmdNext 
  49.       Caption         =   ">"
  50.       BeginProperty Font 
  51.          Name            =   "Arial"
  52.          Size            =   14.25
  53.          Charset         =   0
  54.          Weight          =   400
  55.          Underline       =   0   'False
  56.          Italic          =   0   'False
  57.          Strikethrough   =   0   'False
  58.       EndProperty
  59.       Height          =   375
  60.       Left            =   3960
  61.       Style           =   1  'Graphical
  62.       TabIndex        =   4
  63.       Top             =   5520
  64.       Width           =   495
  65.    End
  66.    Begin VB.CommandButton cmdBack 
  67.       Caption         =   "<"
  68.       BeginProperty Font 
  69.          Name            =   "Arial"
  70.          Size            =   14.25
  71.          Charset         =   0
  72.          Weight          =   400
  73.          Underline       =   0   'False
  74.          Italic          =   0   'False
  75.          Strikethrough   =   0   'False
  76.       EndProperty
  77.       Height          =   375
  78.       Left            =   2400
  79.       Style           =   1  'Graphical
  80.       TabIndex        =   3
  81.       Top             =   5520
  82.       Width           =   495
  83.    End
  84.    Begin VB.CommandButton btnFirst 
  85.       Caption         =   "I<"
  86.       BeginProperty Font 
  87.          Name            =   "Arial"
  88.          Size            =   14.25
  89.          Charset         =   0
  90.          Weight          =   400
  91.          Underline       =   0   'False
  92.          Italic          =   0   'False
  93.          Strikethrough   =   0   'False
  94.       EndProperty
  95.       Height          =   375
  96.       Left            =   1920
  97.       Style           =   1  'Graphical
  98.       TabIndex        =   2
  99.       Top             =   5520
  100.       Width           =   495
  101.    End
  102.    Begin VCF150Ctl.F1Book F1Book1 
  103.       Height          =   4455
  104.       Left            =   240
  105.       TabIndex        =   1
  106.       Top             =   960
  107.       Width           =   9135
  108.       _ExtentX        =   16113
  109.       _ExtentY        =   7858
  110.       _0              =   $"frmMain.frx":0000
  111.       _1              =   $"frmMain.frx":0405
  112.       _2              =   $"frmMain.frx":080A
  113.       _3              =   $"frmMain.frx":0C0F
  114.       _4              =   $"frmMain.frx":1014
  115.       _5              =   $"frmMain.frx":1419
  116.       _6              =   $"frmMain.frx":181E
  117.       _7              =   $"frmMain.frx":1C23
  118.       _8              =   $"frmMain.frx":2028
  119.       _9              =   $"frmMain.frx":242D
  120.       _count          =   10
  121.       _ver            =   1
  122.    End
  123.    Begin VB.Label Label3 
  124.       Caption         =   "Record"
  125.       BeginProperty Font 
  126.          Name            =   "Tahoma"
  127.          Size            =   12
  128.          Charset         =   0
  129.          Weight          =   400
  130.          Underline       =   0   'False
  131.          Italic          =   0   'False
  132.          Strikethrough   =   0   'False
  133.       EndProperty
  134.       ForeColor       =   &H80000002&
  135.       Height          =   255
  136.       Left            =   960
  137.       TabIndex        =   8
  138.       Top             =   5520
  139.       Width           =   855
  140.    End
  141.    Begin VB.Label lblRecordNo 
  142.       Alignment       =   2  'Center
  143.       BackColor       =   &H8000000E&
  144.       BorderStyle     =   1  'Fixed Single
  145.       Caption         =   "1 of 15"
  146.       BeginProperty Font 
  147.          Name            =   "Tahoma"
  148.          Size            =   8.25
  149.          Charset         =   0
  150.          Weight          =   400
  151.          Underline       =   0   'False
  152.          Italic          =   0   'False
  153.          Strikethrough   =   0   'False
  154.       EndProperty
  155.       ForeColor       =   &H80000002&
  156.       Height          =   375
  157.       Left            =   2880
  158.       TabIndex        =   7
  159.       Top             =   5520
  160.       Width           =   1095
  161.    End
  162.    Begin VB.Label Label1 
  163.       Alignment       =   2  'Center
  164.       BorderStyle     =   1  'Fixed Single
  165.       Caption         =   "Smallville Genealogical Society"
  166.       BeginProperty Font 
  167.          Name            =   "Tahoma"
  168.          Size            =   24
  169.          Charset         =   0
  170.          Weight          =   700
  171.          Underline       =   0   'False
  172.          Italic          =   -1  'True
  173.          Strikethrough   =   0   'False
  174.       EndProperty
  175.       ForeColor       =   &H80000002&
  176.       Height          =   735
  177.       Left            =   240
  178.       TabIndex        =   0
  179.       Top             =   120
  180.       Width           =   9135
  181.    End
  182. Attribute VB_Name = "frmMain"
  183. Attribute VB_GlobalNameSpace = False
  184. Attribute VB_Creatable = False
  185. Attribute VB_PredeclaredId = True
  186. Attribute VB_Exposed = False
  187. Dim NewRecord As Boolean
  188. Dim CurrentRow As Integer
  189. Dim Formatting As Boolean
  190. Private Sub btnFirst_Click()
  191.     With F1Book1
  192.         .SetActiveCell 1, 1
  193.         .ShowActiveCell
  194.         .SetFocus
  195.     End With
  196. End Sub
  197. Private Sub cmdBack_Click()
  198.     With F1Book1
  199.         .SetActiveCell (F1Book1.Row - 1), 1
  200.         .ShowActiveCell
  201.         .SetFocus
  202.     End With
  203. End Sub
  204. Private Sub cmdLast_Click()
  205.      With F1Book1
  206.         .SetActiveCell .MaxRow, 1
  207.         .ShowActiveCell
  208.         .SetFocus
  209.     End With
  210. End Sub
  211. Private Sub cmdNew_Click()
  212.     With F1Book1
  213.         .MaxRow = .MaxRow + 1
  214.         .SetActiveCell .MaxRow, 1
  215.         .ShowActiveCell
  216.         .SetFocus
  217.         
  218.         NewRecord = True
  219.         .NumberRC(.MaxRow, 1) = .NumberRC(.MaxRow - 1, 1) + 1
  220.         .TextRC(.MaxRow, 4) = "Male"
  221.     End With
  222. End Sub
  223. Private Sub cmdNext_Click()
  224.     With F1Book1
  225.         .SetActiveCell (.Row + 1), 1
  226.         .ShowActiveCell
  227.         .SetFocus
  228.     End With
  229. End Sub
  230. Private Sub F1Book1_KeyDown(KeyCode As Integer, Shift As Integer)
  231.    Dim Response As Integer
  232.    Dim pRetCode As Integer
  233.    Dim thisRow As Integer
  234.    With F1Book1
  235.         '' In this event we are going to handle the Delete key ourselves.
  236.         '' In the FormActivate event we have set AllowDelete to false, so the
  237.         '' default behavior for the Delete Key is overridden.  First we will
  238.         '' test for the Delete Key, and if we find it, we will make sure that
  239.         '' the end user really intends to delete this record.
  240.         If KeyCode = 46 Then
  241.              Response = MsgBox("Delete Current Record?", vbYesNo, "Formula One")
  242.              If Response = vbYes Then
  243.                   thisRow = .Row
  244.                   '' we call ODBCPrepare with the proper DELETE FROM syntax with the
  245.                   '' information for the current row.  Then we will execute this
  246.                   '' SQLStatement
  247.                   pRetCode = .ODBCPrepareEx("DELETE FROM Memberships WHERE ID = " & Str(.NumberRC(thisRow, 1)))
  248.                   pRetCode = .ODBCExecuteEx(thisRow, thisRow)
  249.                   '' Now we delete the row from the Spreadsheet
  250.                   .DeleteRange thisRow, 1, thisRow, 256, F1ShiftRows
  251.                   '' if we don't set Modified to False, the next time we
  252.                   '' change the selection, the changes to the row will be
  253.                   '' 'saved' to the database
  254.                   .Modified = False
  255.                   '' now we adjust the MaxRow to compensate for the
  256.                   '' deleted row
  257.                   .MaxRow = .MaxRow - 1
  258.                   '' if this was the last record, we will want to move the
  259.                   '' selection to the new last record
  260.                   If .MaxRow + 1 = thisRow Then
  261.                      .Row = thisRow - 1
  262.                   End If
  263.                   SetPattern
  264.                  
  265.              End If
  266.          End If
  267.     End With
  268. End Sub
  269. Private Sub F1Book1_ObjClick(ObjName As String, ByVal ObjID As Long)
  270. Const cmdCol = 4
  271.     Dim text As String
  272.     With F1Book1
  273.     Select Case ObjName
  274.     '' the command button is the only one
  275.     '' with an action
  276.     '' the click will toggle the text
  277.     '' on the button and set the text
  278.     '' underneath
  279.     '' the toggle is based on the cell text due
  280.     '' to the possibility of bad data
  281.     Case "cmdSex"
  282.         text = .ObjText(ObjID)
  283.         Select Case text
  284.         Case "Male"
  285.             .TextRC(.Row, cmdCol) = "Female"
  286.             .ObjText(ObjID) = "Female"
  287.         Case Else
  288.             .TextRC(.Row, cmdCol) = "Male"
  289.             .ObjText(ObjID) = "Male"
  290.         End Select
  291.     Case "cboAncestry"
  292.         '' combo updates cell directly
  293.     Case "chkMemberStatus"
  294.         '' updated through ObjValueChanged event
  295.     End Select
  296.     End With
  297. End Sub
  298. Private Sub F1Book1_ObjValueChanged(ObjName As String, ByVal ObjID As Long)
  299. Const chkCol = 6
  300.     With F1Book1
  301.     Select Case ObjName
  302.     Case "cmdSex"
  303.         '' this is handled in the ObjClick event
  304.     Case "cboAncestry"
  305.         '' combo updates the cell directly
  306.     Case "chkMemberStatus"
  307.         .NumberRC(.Row, chkCol) = .ObjValue(ObjID)
  308.     End Select
  309.     End With
  310. End Sub
  311. Private Sub F1Book1_ODBCExecuteError(ByVal nRow As Long, ByVal nCol As Long, pAction As Integer)
  312.     pAction = F1ODBCErrorAbort
  313. End Sub
  314. Private Sub F1Book1_SelChange()
  315. Dim Unchanged As Boolean
  316.     ''since the SelChange event fires even
  317.     ''when moving to a new cell in the same
  318.     ''row, we will test so that we only
  319.     ''do an update when we move to a new row
  320.     Unchanged = False
  321.     With F1Book1
  322.     If .Modified Then
  323.         If CurrentRow <> .Row Then
  324.             UpdateRecord
  325.         Else
  326.             Unchanged = True
  327.         End If
  328.     End If
  329.      
  330.     UpdateControlsLocation
  331.     .Modified = False
  332.     If NewRecord And Unchanged Then
  333.         ' we do nothing
  334.     Else
  335.         NewRecord = False
  336.     End If
  337.     CurrentRow = .Row
  338.     End With
  339. End Sub
  340. Private Sub Form_Activate()
  341.    Dim pConnect As New F1ODBCConnect
  342.     Dim pRetCode As Integer
  343.     Dim pQuery As New F1ODBCQuery
  344.     Dim i As Integer
  345.     With F1Book1
  346.             '' we set AllowDelete to False so that we can do our
  347.             '' own Delete routine in the KeyPress event
  348.             .AllowDelete = False
  349.             .ShowSelections = F1On
  350.             .RowMode = True
  351.             '' We define our Connect String and connect to the Database
  352.             pConnect.ConnectStr = "DSN=Smallville Genealogy;DBQ=" & App.Path & "\demo6.mdb;DefaultDir=" & App.Path & ";DriverId=25;FIL=MS"
  353.         On Error GoTo ConnectError
  354.             .ODBCConnectEx pConnect, True
  355.             '' next we prepare to run our Query
  356.             pQuery.QueryStr = "Select * from Memberships"
  357.             pQuery.SetColNames = False
  358.             pQuery.SetColFormats = False
  359.             pQuery.SetColWidths = False
  360.             pQuery.SetMaxRC = True
  361.             
  362.             .ODBCQueryEx pQuery, 1, 1, False
  363.             '' we'll call a DoEvents to give the Query time to run before updating the control positions
  364.             DoEvents
  365.             UpdateControlsLocation
  366.             '' We set the Modified property to False so that we can trap
  367.             '' when we need to save changes to our database
  368.             .Modified = False
  369.             NewRecord = False
  370.             CurrentRow = F1Book1.Row
  371.             
  372.             SetPattern
  373.             .SetActiveCell 1, 1
  374.             .ShowActiveCell
  375.     End With
  376.     Exit Sub
  377. ConnectError:
  378.    MsgBox "Make sure that you have named the Database ""Smallville Genealogy"" in the ODBC Setup", vbOKOnly, "ODBC Error"
  379. End Sub
  380. Public Sub UpdateControlsLocation()
  381.     ' for easy changes later
  382.     Const cmdID = 1
  383.     Const cboID = 2
  384.     Const chkID = 3
  385.     Const cmdCol = 4
  386.     Const cboCol = 5
  387.     Const chkCol = 6
  388.     Dim text As String
  389.     Dim thisRow As Integer
  390.     Dim value As Double
  391.     thisRow = F1Book1.Row
  392.      If thisRow = 1 Then
  393.         cmdBack.Enabled = False
  394.     Else
  395.         cmdBack.Enabled = True
  396.     End If
  397.     If thisRow = F1Book1.MaxRow Then
  398.         cmdNext.Enabled = False
  399.     Else
  400.         cmdNext.Enabled = True
  401.     End If
  402.      
  403.     lblRecordNo.Caption = Str(thisRow) & " of " & Str(F1Book1.MaxRow)
  404.     With F1Book1
  405.         .ObjSetPos cmdID, (cmdCol - 1), (thisRow - 1), cmdCol, thisRow
  406.         .ObjText(cmdID) = F1Book1.TextRC(thisRow, cmdCol)
  407.         
  408.         .ObjSetPos cboID, (cboCol - 1), (thisRow - 1), cboCol, thisRow + 5
  409.         .ObjSetCell cboID, F1ControlCellValue, thisRow, cboCol
  410.         .ObjValue(cboID) = .NumberRC(thisRow, cboCol)
  411.         
  412.         .ObjSetPos chkID, (chkCol - 0.97), (thisRow - 0.97), (chkCol - 0.01), (thisRow - 0.03)
  413.         .ObjSetCell chkID, 0, thisRow, chkCol
  414.         .ObjValue(chkID) = .NumberRC(thisRow, chkCol)
  415.     End With
  416. End Sub
  417. Public Sub SetPattern()
  418. Formatting = True
  419. With F1Book1
  420. .Repaint = False
  421. For i = 1 To .MaxRow
  422.         If i Mod 2 = 0 Then
  423.             .SetSelection i, -1, i, -1
  424.             .SetPattern 1, .PaletteEntry(2), .PaletteEntry(2)
  425.             .SetBorder -1, 1, 1, 1, 1, 1, vbBlack, vbBlack, vbBlack, vbBlack, vbBlack
  426.         Else
  427.             .SetSelection i, -1, i, -1
  428.             .SetPattern 1, .PaletteEntry(42), .PaletteEntry(1)
  429.             .SetBorder -1, 1, 1, 1, 1, 1, vbBlack, vbBlack, vbBlack, vbBlack, vbBlack
  430.         End If
  431.     Next i
  432.     .Repaint = True
  433. End With
  434. Formatting = False
  435. End Sub
  436. Private Sub Form_Unload(Cancel As Integer)
  437.     F1Book1.ODBCDisconnect
  438. End Sub
  439. Public Sub UpdateRecord()
  440. Dim pRetCode As Integer
  441. With F1Book1
  442.     If Not Formatting Then
  443.         If NewRecord Then
  444.             pRetCode = .ODBCPrepareEx("INSERT INTO Memberships  VALUES (?, ?, ?, ?, ?, ?, ?)")
  445.             pRetCode = .ODBCBindParameterEx(1, 1, F1CDataLong)
  446.             pRetCode = .ODBCBindParameterEx(2, 2, F1CDataChar)
  447.             pRetCode = .ODBCBindParameterEx(3, 3, F1CDataChar)
  448.             pRetCode = .ODBCBindParameterEx(4, 4, F1CDataChar)
  449.             pRetCode = .ODBCBindParameterEx(5, 5, F1CDataLong)
  450.             pRetCode = .ODBCBindParameterEx(6, 6, F1CDataLong)
  451.             pRetCode = .ODBCBindParameterEx(7, 7, F1CDataDate)
  452.             pRetCode = .ODBCExecuteEx(.MaxRow, .MaxRow)
  453.             SetPattern
  454.         Else
  455.             pRetCode = .ODBCPrepareEx("UPDATE Memberships SET FirstName=?, LastName=?, Sex=?, Ancestry=?, MemberStatus=?, DuesPaidDate=? WHERE ID=?")
  456.             pRetCode = .ODBCBindParameterEx(1, 2, F1CDataChar)
  457.             pRetCode = .ODBCBindParameterEx(2, 3, F1CDataChar)
  458.             pRetCode = .ODBCBindParameterEx(3, 4, F1CDataChar)
  459.             pRetCode = .ODBCBindParameterEx(4, 5, F1CDataLong)
  460.             pRetCode = .ODBCBindParameterEx(5, 6, F1CDataLong)
  461.             pRetCode = .ODBCBindParameterEx(6, 7, F1CDataDate)
  462.             pRetCode = .ODBCBindParameterEx(7, 1, F1CDataLong)
  463.             pRetCode = .ODBCExecuteEx(CurrentRow, CurrentRow)
  464.         End If
  465.     End If
  466.     End With
  467. End Sub
  468.